package com.larosa.practice.domain;

import com.larosa.practice.strategy.FullReductionStrategy;
import com.larosa.practice.strategy.StrawberryDiscountStrategy;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.math.BigDecimal;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * @Author: larosa
 * @Description: 第四个问题的测试类
 * @DateTime: 2025/2/9 11:21
 **/
@SpringBootTest
class SupermarketTest4 {
    /**
     * 促销活动效果明显，超市继续加大促销力度，购物满 100 减 10 块。现在顾客 D 在超市购买了若干斤苹果、 草莓和芒果，需计算一共需要多少钱？
     * 请编写函数，对于 D 购买的水果斤数 (水果斤数为大于等于 0 的整数)，计算并返回所购买商品的总价。
     * 针对大于100和不大于100的情况测试
     */
    @Test
    public void testDOne() {
        //买3斤苹果，4斤草莓，2斤芒果 3*8 + 4*13*0.8 + 2*20 = 105.6  （105.6达到满减标准,故实际应付95.6）
        Supermarket supermarket = new Supermarket(new FullReductionStrategy());//使用满减策略
        int appleQuantity = 3;
        int strawberryQuantity = 4;
        int mangoQuantity = 2;
        BigDecimal strawberryDiscountedTotal = new StrawberryDiscountStrategy().calculateTotalPrice(appleQuantity, strawberryQuantity, mangoQuantity);
        BigDecimal expected = strawberryDiscountedTotal.compareTo(new BigDecimal("100")) >= 0 ?
                strawberryDiscountedTotal.subtract(new BigDecimal("10")) : strawberryDiscountedTotal;
        System.out.println("预期花费：" + expected + "元");
        BigDecimal actual = supermarket.calculateTotalPrice(appleQuantity, strawberryQuantity, mangoQuantity);
        System.out.println("实际花费：" + actual + "元");
        assertEquals(expected, actual);
    }

    @Test
    public void testDTwo() {
        //买3斤苹果，7斤草莓，不购买芒果 8*3 + 7*13*0.8 =96.8 （96.8未达到满减标准，故应付96.8）
        Supermarket supermarket = new Supermarket(new FullReductionStrategy());//使用满减策略
        int appleQuantity = 3;
        int strawberryQuantity = 7;
        int mangoQuantity = 0;
        BigDecimal strawberryDiscountedTotal = new StrawberryDiscountStrategy().calculateTotalPrice(appleQuantity, strawberryQuantity, mangoQuantity);
        BigDecimal expected = strawberryDiscountedTotal.compareTo(new BigDecimal("100")) >= 0 ?
                strawberryDiscountedTotal.subtract(new BigDecimal("10")) : strawberryDiscountedTotal;
        System.out.println("预期花费：" + expected + "元");
        BigDecimal actual = supermarket.calculateTotalPrice(appleQuantity, strawberryQuantity, mangoQuantity);
        System.out.println("实际花费：" + actual + "元");
        assertEquals(expected, actual);
    }
}